package com.mstore.dao;

import java.util.List;

import com.mstore.pojo.ThirdAct;

/**
 * 
 * 微信开发第三方凭证
 * 
 */
public class ThirdActDao extends SuperDao {

	public void save(ThirdAct thirdact) {
		super.save(thirdact);
	}

	/**
	 * 微信开发第三方凭证修改
	 * 
	 */
	public void update(ThirdAct thirdact) {
		/*
		 * String sql = "update b_third_account set appId = '" +
		 * thirdact.getAppId() + "', appSecret = '" + thirdact.getAppSecret() +
		 * "', name = '" + thirdact.getName() + "', weixinName = '" +
		 * thirdact.getWeixinName() + "', ysId = '" + thirdact.getYsId() +
		 * "' where id = " + thirdact.getId(); super.executeUpdate(sql);
		 */

		StringBuilder sb = new StringBuilder();
		sb.append("update b_third_account set appId = '");
		sb.append(thirdact.getAppId());
		sb.append("', appSecret = '");
		sb.append(thirdact.getAppSecret());
		sb.append("', name = '");
		sb.append(thirdact.getName());
		sb.append("', weixinName = '");
		sb.append(thirdact.getWeixinName());
		sb.append("', ysId = '");
		sb.append(thirdact.getYsId());
		sb.append("' where id = ");
		sb.append(thirdact.getId());
		super.executeUpdate(sb.toString());
	}

	/**
	 * 获取企业第三方凭证信息
	 */
	public List<Object> getAll(ThirdAct thirdact) {
		String hql = "from ThirdAct where eaId=?";
		List<Object> act = super.getObject(hql,
				new Object[] { thirdact.getEaId() });
		if (act.size() != 0) {
			return act;
		}
		else {
			return null;
		}
	}

	public List<Object> getThirdActByYsId(ThirdAct thirdact) {
		String hql = "from ThirdAct where ysId=? and id != ?";
		List<Object> act = super.getObject(hql,
				new Object[] { thirdact.getYsId(), thirdact.getId() });
		if (act.size() != 0) {
			return act;
		}
		else {
			return null;
		}
	}

}
